#pragma once
#include <memory>
#include <thread>
#include "tensor.h"
#include "thread_safe_queue.h"

struct AVFormatContext;
struct AVCodecContext;

class FfmVideoReader {
   public:
    FfmVideoReader();
    ~FfmVideoReader();
    void open(const char* videoPath);
    void close();
    void stay();
    std::shared_ptr<Tensor<unsigned char>> pop();

   public:
    int width;
    int height;

   private:
    void decodeVideoStream();

   private:
    std::string videoPath_;
    AVFormatContext* formatContext_ = nullptr;
    int videoStreamIndex_ = -1;
    AVCodecContext* codecContext_ = nullptr;

    ThreadSafeQueue<std::shared_ptr<Tensor<unsigned char>>> rgbDataQue_;
    int duration_;
    std::thread* decodeTh_ = nullptr;
    bool isLive_ = false;
    volatile bool isPlaying_ = true;
};